﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Marbles.Core.Controls
{
    [ToolboxData("<{0}:WebSlice runat=server></{0}:WebSlice>")]
    public class WebSlice : Panel
    {
        public string Title
        {
            get
            {
                object obj = ViewState["title"];
                if (obj == null) { return string.Empty; }
                return obj.ToString();
            }
            set { ViewState["title"] = value; }
        }

        public bool ShowTitle
        {
            get
            {
                object obj = ViewState["showtitle"];
                if (obj == null) { return true; }
                return Convert.ToBoolean(obj);
            }
            set { ViewState["showtitle"] = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {            
            this.CssClass = "hslice";
            base.OnPreRender(e);
        }

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            if (!ShowTitle) { writer.AddStyleAttribute("display", "none"); }
            writer.AddAttribute("class", "entry-title");
            writer.RenderBeginTag(HtmlTextWriterTag.H2);
            writer.Write(this.Title);
            writer.RenderEndTag();

            writer.AddAttribute("class", "entry-content");
            writer.RenderBeginTag(HtmlTextWriterTag.P);
            base.RenderContents(writer);
            writer.RenderEndTag();
        }
    }
}
